namespace nwind {
    using System;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Linq;
    using System.Linq.Expressions;
    using System.Data;
    using System.Data.Linq;


    public partial class NorthwindInheritance : DataContext {
        public Table<BaseContact> Contacts;

        public NorthwindInheritance(string connection)
            : base(connection) {
        }

        public NorthwindInheritance(System.Data.IDbConnection connection)
            : base(connection) {
        }
    }

    /*
     *                  Contact
     *                 /      \
     *       ShipperContact   FullContact (abstract)
     *                       /     |     \
     *               Customer   Employee  Supplier
     *               Contact    Contact   Contact
     */
    [Table(Name = "Contacts")]
    [InheritanceMapping(Code = "Unknown", Type = typeof(BaseContact), IsDefault = true)]
    [InheritanceMapping(Code = "Customer", Type = typeof(CustomerContact))]
    [InheritanceMapping(Code = "Supplier", Type = typeof(SupplierContact))]
    [InheritanceMapping(Code = "Employee", Type = typeof(EmployeeContact))]
    [InheritanceMapping(Code = "Shipper", Type = typeof(ShipperContact))]
    public class BaseContact {
        [Column(DBType = "INT NOT NULL", IsPrimaryKey = true, IsDBGenerated = true)]
        public int ContactID;

        [Column(DBType = "NVARCHAR(50)", IsDiscriminator = true)]
        public string ContactType;

        [Column(DBType = "NVARCHAR(40)")]
        public string CompanyName;

        [Column(DBType = "NVARCHAR(24)")]
        public string Phone;
    }

    public class ShipperContact : BaseContact {
    }

    public abstract class FullContact : BaseContact {
        [Column(DBType = "NVARCHAR(40)")]
        public string ContactName;

        [Column(DBType = "NVARCHAR(30)")]
        public string ContactTitle;

        [Column(DBType = "NVARCHAR(60)")]
        public string Address;

        [Column(DBType = "NVARCHAR(15)")]
        public string City;

        [Column(DBType = "NVARCHAR(15)")]
        public string Region;

        [Column(DBType = "NVARCHAR(10)")]
        public string PostalCode;

        [Column(DBType = "NVARCHAR(15)")]
        public string Country;

        [Column(DBType = "NVARCHAR(24)")]
        public string Fax;
    }

    public class SupplierContact : FullContact {
        [Column(DBType = "NTEXT")]
        public string HomePage;
    }

    public class CustomerContact : FullContact {
    }

    public class EmployeeContact : FullContact {
        [Column(DBType = "NVARCHAR(4)")]
        public string Extension;

        [Column(DBType = "NVARCHAR(255)")]
        public string PhotoPath;

        [Column(DBType = "IMAGE")]
        public byte[] Photo;
    }
}
